﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

using ZLDC.Common.Estate;
using ZLDC.Topo.Model.Estate;


namespace ZLDC.Topo.BLL.Estate
{
    public class RoomNoBLL
    {

        public int AddRoomNos(string name, string oname, int floor, int bid, string bname, string mark, string type, string id, string usage, string cUname, string cDept, string cDeptid, string status, string namepy, string othernamepy, int isvalid)
        {
            return ZLDC.DAL.Estate.RoomNoDAL.AddRoomNos(name, oname, floor, bid, bname, mark, type, id, usage, cUname, cDept, cDeptid, status, namepy, othernamepy, isvalid);
        }
        public DataTable SelectFLoorByBid(int bid)
        {
            return ZLDC.DAL.Estate.RoomNoDAL.SelectFLoorByBid(bid);
                                }
        public DataTable SelectFLoorByBid(int bid, string flor)
        {
            return ZLDC.DAL.Estate.RoomNoDAL.SelectFLoorByBid(bid, flor);
                                }
        public static string SelectNameByFloor(string floor, int bid)
        {
            DataTable dt = (DataTable)ZLDC.DAL.Estate.RoomNoDAL.SelectNameByFloor(floor, bid);
            _Json json = new _Json(dt);
            return "{record:" + json.ToJson() + "}";
                    }
        public DataSet SelectRoomsById(string id)
        {
            return ZLDC.DAL.Estate.RoomNoDAL.SelectRoomsById(id);
        }

        public static string SelectRoomNoList(int page, int pagesize, int total, int typeid)
        {
            DataTable dt = ZLDC.DAL.Estate.RoomNoDAL.p_roomno_list_table(page, pagesize, total, typeid, new _Database("estate"));
            _Json json = new _Json(dt);
            return "{record:" + json.ToJson() + "}";
        }
        public DataSet SelectNameByBid(int bid)
        {
            return ZLDC.DAL.Estate.RoomNoDAL.SelectNameByBid(bid);
        }
        public int SelectMaxFloorByBid(int bid)
        {
            return ZLDC.DAL.Estate.RoomNoDAL.SelectMaxFloorByBid(bid);
        }
        public static int DeleteNameById(int id)
        {
            return ZLDC.DAL.Estate.RoomNoDAL.DeleteNameById(id);
        }
        
        public static int DeleteNameByIdAndIsValid(int id)
        {
            return ZLDC.DAL.Estate.RoomNoDAL.DeleteNameByIdAndIsValid(id);
        }
        public static int UpdateOtherName(string id, string oname, string type, string tablename, string commitName, string commitDept, string commitDeptID)
        {
            return ZLDC.DAL.Estate.RoomNoDAL.UpdateOtherName(id, oname, type, tablename, commitName, commitDept, commitDeptID);
        }
        public static int SelectRooms(string bid, string floor, string name) 
        {
            return ZLDC.DAL.Estate.RoomNoDAL.SelectRooms(bid, floor, name);
        }

        public static string SelectRoomsJson(string bid, string floor, string name)
        {
            DataSet ds = ZLDC.DAL.Estate.RoomNoDAL.SelectRoomsJson(bid, floor, name);

            if (ds.Tables.Count > 0 && ds != null && ds.Tables[0].Rows.Count > 0)
            {

                _Json json = new _Json(ds.Tables[0]);
                return "{record:" + json.ToJson() + "}";
            }
            else
            {
                return "{record:''}";
            }

        }
                public static void UpdateStatusOrUsageByID(string usage, string bstatus, int id)
        {
            ZLDC.DAL.Estate.RoomNoDAL.UpdateStatusOrUsageByID(usage, bstatus, id);
        }

                                                                public static string RoomNoList(int page, int pagesize, string condition)
        {
            DataTable dt = null;
            int total = 0;                       int pageall = 0;         
            using (_Database db = new _Database("estate"))
            {
                dt = ZLDC.DAL.Estate.RoomNoDAL.p_roomno_list_condition_table(page, pagesize, condition, ref total, db);
            }

            pageall = _Utility.GetPageAll(pagesize, total);      
            _Json json = new _Json(dt);
            return "{page:{currentpage:'" + page + "',pagesize:'" + pagesize + "',total:'" + total + "',pageall:'" + pageall + "'},record:" + json.ToJson() + "}";
        }

                                                public static string RoomnoCheck(int id)
        {
            string outmsg = "房号审核失败";
            int rows = 0;

            using (_Database db = new _Database("estate"))
            {
                rows = ZLDC.DAL.Estate.RoomNoDAL.RoomnoCheck(id, db);
                if (rows > 0)
                    outmsg = "房号审核成功";
            }

            return outmsg;
        }

        public static string RoomnoCheck(int id, int isvalid, string Approval_views)
        {
            string outmsg = "房号审核失败";
            int rows = 0;

            using (_Database db = new _Database("estate"))
            {
                rows = ZLDC.DAL.Estate.RoomNoDAL.RoomnoCheck(id,isvalid,Approval_views, db);
                if (rows > 0)
                    outmsg = "房号审核成功";
            }

            return outmsg;
        }

                                                        public static string p_v_roomno_list_table(int page, int pagesize, string condition)
        {
            DataTable dt = null;
            int total = 0;                       int pageall = 0;         
            using (_Database db = new _Database("estate"))
            {
                dt = ZLDC.DAL.Estate.RoomNoDAL.p_v_roomno_list_table(page, pagesize, condition, ref total, db);
            }

            pageall = _Utility.GetPageAll(pagesize, total);      
            _Json json = new _Json(dt,1);
            return "{page:{currentpage:'" + page + "',pagesize:'" + pagesize + "',total:'" + total + "',pageall:'" + pageall + "'},record:" + json.ToJson() + "}";
        }



                                                        public static string p_v_roomno_list_table(string condition,string roomnoid)
        {
            DataTable dt = null;
            using (_Database db = new _Database("estate"))
            {
                dt = ZLDC.DAL.Estate.RoomNoDAL.ls_roomnoList(condition,roomnoid);
            }
            _Json json = new _Json(dt, 1);
            return "{page:{currentpage:'"+dt.Rows.Count+"'},record:" + json.ToJson() + "}";
        }

                                                        public static string p_v_roomno_ss( string roomnoid,int eid,string type)
        {
            DataTable dt = null;
            using (_Database db = new _Database("estate"))
            {
                dt = ZLDC.DAL.Estate.RoomNoDAL.ls_roomnoList_ss(roomnoid,eid, type);
            }
            _Json json = new _Json(dt, 1);
            return "{page:{currentpage:'" + dt.Rows.Count + "'},record:" + json.ToJson() + "}";
        }
                                                                public static string p_getHousingIDByRoomID(int roomid, int tradetype)
        {            
            string outmsg = "";

            using (_Database db = new _Database("estate"))
            {
                int housingid = ZLDC.DAL.Estate.RoomNoDAL.p_getHousingIDByRoomID(roomid, tradetype, out outmsg, db);
                if (housingid > 0)
                    outmsg = housingid.ToString();
            }

            return outmsg;
        }
                                                public static int SelectRoomNoCountByBid(int bid)
        {
            int count = 0;
            using (_Database db = new _Database("estate"))
            {
                count = ZLDC.DAL.Estate.RoomNoDAL.SelectRoomNoCountByBid(bid, db);

            }

            return count;
        }
        
    }
}
